package com.kfm.jdbc.day0324.model;

import com.kfm.jdbc.day0324.Recover;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class User {

    private Integer id;
    private String name;
    private String password;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                '}';
    }

    public static class UsersRecover implements Recover<User> {

        @Override
        public List<User> recover(ResultSet set) throws SQLException {
            List<User> users = new ArrayList<>();
            while (set.next()) {
                User user = new User();
                user.setId(set.getInt(1));
                user.setName(set.getString(2));
                user.setPassword(set.getString(3));
                users.add(user);
            }
            return users;
        }
    }
}
